import { request } from './request.js'
// import axios from 'axios'
// 登录请求
export const apiLogin = (options) => {
  return request({
    method: options.method,
    url: options.url,
    data: options.data
  })
}
//  发送验证码
export const apiLoginSendCode = options => {
  return request({
    method: options.method,
    url: options.url
  })
}

// 获取用户自己的信息请求
export const mineUserInfo = options => {
  return request({
    method: options.method,
    url: options.url
  })
}

export const apiHomeGetChannels = () => {
  return request({
    method: 'get',
    url: '/app/v1_0/user/channels'
  })
}
export const apiRecommendChannels = params => {
  console.log(params)
  return request({
    method: 'get',
    url: '/app/v1_1/articles',
    params
  })
}

export const apiGetAllChannels = () => {
  return request({
    method: 'get',
    url: `/app/v1_0/channels`
  })
}

export const apiGetSuggestion = (q) => {
  return request({
    method: 'get',
    url: '/app/v1_0/suggestion',
    params: { q }
  })
}
// /app/v1_0/search
export const apiGetResultValue = (params) => {
  return request({
    method: 'get',
    url: '/app/v1_0/search',
    params
  })
}
// 获取新闻文章详情   /app/v1_0/articles/:article_id
export const apiGetArticleFollow = (articleId) => {
  return request({
    method: 'get',
    url: `/app/v1_0/articles/${articleId}`
  })
}

// 关注用户   /app/v1_0/user/followings
export const followUser = (target) => {
  return request({
    method: 'post',
    url: '/app/v1_0/user/followings',
    data: { target }
  })
}
//  取消关注用户   /app/v1_0/user/followings/:target

export const cancleFllow = (target) => {
  return request({
    method: 'delete',
    url: `/app/v1_0/user/followings/${target}`
  })
}
//  收藏文章  /app/v1_0/article/collections

export const apiCollectArticle = (target) => {
  return request({
    method: 'post',
    url: `/app/v1_0/article/collections`,
    data: { target }
  })
}
//  取消收藏文章  /app/v1_0/article/collections/:target

export const apiCancleCollectArticle = (target) => {
  return request({
    method: 'delete',
    url: `/app/v1_0/article/collections/${target}`
  })
}
//  点赞  /app/v1_0/article/likings
export const apiAddLikings = target => request({
  method: 'post',
  url: `/app/v1_0/article/likings`,
  data: { target }
})

// 取消点赞 /app/v1_0/article/likings/:target
export const apiCancleLikings = target => request({
  method: 'delete',
  url: `/app/v1_0/article/likings/${target}`
})

//  添加新闻文章评论  /app/v1_0/comments
export const apiAddComment = options => request({
  method: 'post',
  url: `/app/v1_0/comments`,
  data: {
    target: options.target,
    content: options.content,
    art_id: options.art_id
  }
})

// 获取新闻文章评论 /app/v1_0/comments
export const apiGetContents = options => request({
  method: 'get',
  url: `/app/v1_0/comments`,
  params: {
    type: 'a',
    source: options.source,
    offset: options.offset || null,
    limit: options.limit || null
  }
})

// export const apiGetContents = options => {
//   console.log(options)
//   return request.get('/app/v1_0/comments', {
//     params: {
//       type: 'a',
//       source: options.source,
//       offset: options.offset || null,
//       limit: options.limit || null
//     }
//   })
// }
